package com.sh4.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.sh4.dao.EnumDao;
import com.sh4.entity.SystemEnum;

@Repository
public class EnumDaoImpl extends BaseDaoImpl<SystemEnum> implements EnumDao{

	@Override
	public int enumCount(String companyCode) {
		
		Criteria c = this.getSession().createCriteria(SystemEnum.class);
		c.add(Restrictions.eq("parentCode", "0"));
		c.setProjection(Projections.rowCount());
		Number count = (Number) c.uniqueResult();
		return  count.intValue();
	}
	
	@Override
	public int enumSonCount(String parentCode) {
		
		Criteria c = this.getSession().createCriteria(SystemEnum.class);
		c.add(Restrictions.eq("parentCode", parentCode));
		c.setProjection(Projections.rowCount());
		Number count = (Number) c.uniqueResult();
		return  count.intValue();
	}

	@Override
	public List<Map<String, Object>> getEnumList(String parentCode) {
		
		String sql = "select e.ENUM_CODE_ as enumCode , e.ENUM_NAME_ as enumName , e.REMARK_ as remark from system_enum e where e.PARENT_CODE_ = ? and e.STATUS_ = '1' order by e.CREATE_DATE_";

		return this.getArrayBySql(sql, parentCode);
	}

}
